<template>
    <div>
        <a-form style="max-width: 500px; margin: 40px auto 0;">
            <a-alert
                    :closable="true"
                    message="模板域代表一个项目工程的文件集!"
                    style="margin-bottom: 24px;"/>
            <a-form-item
                    label="选择数据源配置"
                    :labelCol="{span: 5}"
                    :wrapperCol="{span: 19}"
                    class="stepFormText">
                <a-select placeholder="请选择" v-model="selectedValue">
                    <a-select-option v-for="item in templateGroupList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
                </a-select>
            </a-form-item>
            <a-form-item :wrapperCol="{span: 19, offset: 5}">
                <a-button type="primary" @click="nextStep">下一步</a-button>
                <a-button style="margin-left: 8px" @click="prevStep">上一步</a-button>
            </a-form-item>
        </a-form>
    </div>
</template>

<script>
export default {
  name: "Step2",
  data () {
    return {
      loading: false,
      selectedValue: undefined,
      templateGroupList: []
    }
  },
  methods: {
    nextStep () {
      if (!this.selectedValue) {
        this.$message.error('请选择!')
        return
      }
      this.$emit('nextStep', { templateGroupId: this.selectedValue })
    },
    prevStep () {
      this.$emit('prevStep', { templateGroupId: this.selectedValue })
    }
  },
  mounted() {
    this.Atm.getAction('codeGenerator/generatorTemplateGroup/list')
      .then(res => {
        if (res.code == 0) {
          this.templateGroupList = res.result.records
        } else {
          this.$message.error(res.message)
        }
      })
  }
}
</script>

<style lang="less" scoped>
    .stepFormText {
        margin-bottom: 24px;

        .ant-form-item-label,
        .ant-form-item-control {
            line-height: 22px;
        }
    }

</style>
